﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using QXBook.Model;
using QXBook.Service;
using System.Web;

namespace QXBook.Handlers.AjaxHandlers
{
    public class GetAllPop : AjaxHandler
    {
        public override string GetBusinessData(HttpContext context)
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("var _Popedom=[");
            Dictionary<int, PopDomInfo> allpop = ServiceFactory.CreateInstance<AdminRuleService>().GetAllPopedomEntity();

            if (allpop != null && allpop.Count != 0)
            {
                int i = 0;
                foreach (KeyValuePair<int, PopDomInfo> keyvalue in allpop)
                {
                    sb.Append("{");
                    sb.Append("Id:" + keyvalue.Value.PopID + ",");
                    sb.Append("Name:'" + keyvalue.Value.PopName + "',");
                    sb.Append("ParentId:" + keyvalue.Value.ParentId.ToString() + "");
                    sb.Append("}");
                    i++;
                    if (i != allpop.Count) sb.Append(",");
                }
            }

            sb.Append("];");
            string result = sb.ToString();
            return result;
        }
    }
}
